goog.provide('dkpoints.nav.StandingsHandler');

goog.require('dkpoints.auth.AuthState');
goog.require('dkpoints.standings.Standings');



/**
 * Navigation handler for /#/standings
 * @param {Element} bodyContent The main content element for the page.
 * @param {dkpoints.rpc.RPCService} rpc The RPC service for the app.
 * @param {dkpoints.status.Status} status The status panel.
 * @constructor
 * @implements {dkpoints.nav.Handler}
 */
dkpoints.nav.StandingsHandler = function(bodyContent, rpc, status) {
  /**
   * @type {Element}
   * @private
   */
  this.bodyContent_ = bodyContent;

  /**
   * @type {dkpoints.rpc.RPCService}
   * @private
   */
  this.rpc_ = rpc;

  /**
   * @type {dkpoints.status.Status}
   * @private
   */
  this.status_ = status;

  /**
   * Standings handler prints standings graphs in the body, so whoever's there
   * needs to go away.
   * @type {boolean}
   * @const
   */
  this.disposePrevious = true;
};


/**
 * The auth level required for this module (no authorization required)
 * @type {dkpoints.auth.AuthState}
 * @const
 */
dkpoints.nav.StandingsHandler.prototype.requiredAuth =
    dkpoints.auth.AuthState.NO_AUTH;


/**
 * Display the standings UI.
 * @param {Object} params Required by Handler interface, but Standings_Handler
 *    doesn't have any dynamically set properties, so we'll just ignore it.
 */
dkpoints.nav.StandingsHandler.prototype.handle = function(params) {
  var bodyContent = this.bodyContent_,
      rpc = this.rpc_,
      status = this.status_;

  var standings;
  /**
   * Get or create this instance's Standings presenter.
   * @type {dkpoints.standings.Standings}
   * @private
   */
  this.standings_ = standings = this.standings_ ||
      new dkpoints.standings.Standings(bodyContent, rpc, status);

  standings.render();
};


/**
 * When the handler instance is already active, transition will be called on
 * new navigations instead of handle to allow the handler to more easily
 * transition set up the new state of the active driver instead of rebuilding
 * it from scratch.
 * @param {Object} params An object with request-specific request parameters.
 * @param {function()} handleCancelled Callback to be invoked if user decides
 *    not to navigate away from what they're doing.
 */
dkpoints.nav.StandingsHandler.prototype.transition =
    function(params, handleCancelled) {
};


/**
 * Save state and clear the user-interface so the next handler can use the
 * screen.
 * @param {function(boolean)} onExit Callback once exit is either
 *    complete or cancelled by the user.  Passing true to the callback means
 *    that the handler has relinquished control of thep age; false means
 *    the user opted not to navigate away.
 */
dkpoints.nav.StandingsHandler.prototype.exit = function(onExit) {
  this.standings_.dispose();
  onExit(true);
};
